<script setup>
import { userStore } from '@/stores/models/userStore'
import { getConnect, newMsg } from '@/api/websocket'
import { MessagePlugin } from 'tdesign-vue-next'
import api from '@/api'

const store = userStore()

const get = () => {
  api.post('getStr', {
    Msg: JSON.stringify({
      pageNumber: 4,
      pageSize: 2,
      name: 'zhangzhao',
      id: 1212,
      account: 'sdfsdfsf',
      password: 'dfgdfgd',
      email: 'chazz0504@qq.com'
    })
  })
    .then((res) => {
      console.log(res)
    })
}

const getTest = async () => {
  const res = await api.post('/getUser', {}, { baseURL: '/test' })
  MessagePlugin.success(JSON.stringify(res))
}

const putMsg = async () => {
  const res = await api.post('/socket/push/' + localStorage.getItem('Ip'), { message: 'hello' })
  MessagePlugin.success(res)
}
onMounted(() => {
  getConnect()
})
watch(newMsg, (curVal) => {
  if (curVal) {
    MessagePlugin.closeAll()
    MessagePlugin.success(curVal)
  }
})
</script>
<template>
  首页{{ store.setInfo({ id: 'as', name: 'zhangzhao' }) }}
  {{ store.userinfo }}
  <div class="flex-none w-16 h-16 bg-gray-300"></div>
  <t-button theme="primary" @click="get">getMsg</t-button>
  <t-button theme="primary" @click="putMsg">putMsg</t-button>
  <t-button theme="danger" @click="getTest">错误</t-button>
</template>
<style scoped>

</style>